<?php
/**
 * Talents come from diligence, and knowledge is gained by accumulation.
 *
 * @author: 晋<657306123@qq.com>
 * @date: 2019/8/5 16:09
 */

namespace xin\articlecollect\driver;

use QL\QueryList;
use xin\articlecollect\AbsArticleCollect;

/**
 * 抓取CSDN文章
 *
 * @package xin\articlecollect\driver
 */
class Baijiahao extends AbsArticleCollect{

	/**
	 * 内容解析
	 *
	 * @param string $data HTML内容
	 * @return array
	 */
	public function parse($data){
		$query = QueryList::html($data);
		$title = $query->find('.article-title')->text();

		$createTime = $query->find('.article-source-bjh .date,.article-source-bjh .time')->text();
		$createTime = date_parse_from_format("发布时间：Y-m-d\nH:i", $createTime);
		$createTime = mktime(
			$createTime['hour'],
			$createTime['minute'],
			$createTime['second'],
			$createTime['month'],
			$createTime['day'],
			$createTime['year']
		);

		$viewCount = 0;

		$content = $query->find('.article-content');
		$content = $content->html();

		return [
			'title'       => $title,
			'content'     => $content,
			'view_count'  => $viewCount,
			'create_time' => $createTime,
		];
	}
}
